package com.jsmy.softapp.fragment;

import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jsmy.softapp.MyApp;
import com.jsmy.softapp.R;
import com.jsmy.softapp.activity.CustomerActivity;
import com.jsmy.softapp.aroute.AR;
import com.jsmy.softapp.net.API;
import com.jsmy.softapp.presenter.ZiLiaoPresenter;
import com.jsmy.softapp.util.SPF;
import com.jsmy.softapp.view.ZiLiaoView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created with Android Studio.
 * User: wei_cd.
 * Date: 2018/5/10.
 * Time: 15:36.
 * To change for file | settings | file and code templates.
 */

@Route(path = AR.F_ZILIAO)
public class ZiLiaoFragment extends BaseFragment<ZiLiaoView, ZiLiaoPresenter> implements ZiLiaoView {

    @BindView(R.id.m_webview)
    WebView mWebview;

    @Override
    protected ZiLiaoPresenter createPresenter() {
        return new ZiLiaoPresenter();
    }

    @Override
    protected int setView() {
        return R.layout.fragment_ziliao;
    }

    @Override
    protected void init(View view) {
        mWebview.setVerticalScrollbarOverlay(true); //指定的垂直滚动条有叠加样式
        WebSettings settings = mWebview.getSettings();
        settings.setUseWideViewPort(true);//设定支持viewport
        settings.setJavaScriptEnabled(true);
        settings.setLoadWithOverviewMode(true);
        settings.setBuiltInZoomControls(true);
        settings.setSupportZoom(true);//设定支持缩放
        settings.setDomStorageEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        mWebview.clearHistory();
        mWebview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

                return super.shouldOverrideUrlLoading(view, request);
            }
        });

        mWebview.loadUrl(API.APP_ZILIAO
                + SPF.getString(MyApp.getMyApp(), SPF.SP_ZH, MyApp.getMyApp().bean.getUsername())
                + "&kid="
                + ((CustomerActivity) mActivity).kid);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showLoadingData(String type, Object object) {

    }

    @Override
    public void onDestroyView() {
        presenter.model.disposable.clear();
        super.onDestroyView();
    }

}
